package com.sias.spring.aspect;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.stereotype.Component;

import java.lang.reflect.Method;

/**
 * @author 吴文杰
 * @version 1.0
 * @createTime 2023-05-28 14:02:11
 */
@Aspect
@Component
public class TestAspect {


  @Pointcut(value = "@annotation(com.sias.spring.aspect.AspectAnnotation)")
  public void pointCut() {
  }


  @Around("pointCut()")
  public Object around(ProceedingJoinPoint joinPoint) throws Throwable {
    MethodSignature signature = (MethodSignature) joinPoint.getSignature();
    Method method = signature.getMethod();
    AspectAnnotation annotation = method.getAnnotation(AspectAnnotation.class);
    String value = annotation.value();
    System.out.println(value);
    return null;
  }

  // @Before("execution(public void com.sias.spring.service.UserService.test())")
  // public void around(JoinPoint joinPoint) throws Throwable {
  //   String name = joinPoint.getSignature().getName();
  //   String kind = joinPoint.getKind();
  //   System.out.println(name);
  //   Method test = OrderService.class.getDeclaredMethod("test");
  //   test.invoke(new OrderService());
  // }
}
